<?php
class PropertyTest
{

  private $data = array();  /**  Location for overloaded data.  */

  public $declared = 1;  /**  Overloading not used on declared properties.  */

  private $hidden = 2;  /**  Overloading only used on this when accessed outside the class.  */


  public function __set($name, $value)
  {
    echo "\n\nI am in __set()\n\n";

    echo "Setting '$name' to '$value\n\n";
    $this->data[$name] = $value;
  }

  public function __get($name)
  {
    echo "\n\nI am in __get()\n\n";

    echo "Getting '$name\n\n";
    if (array_key_exists($name, $this->data)) {
        return $this->data[$name];
    }
  }

  /**  As of PHP 5.1.0  */
  public function __isset($name)
  {
    echo "\n\nI am in __isset()\n\n";

    echo "Is '$name' set?\n\n";
    return isset($this->data[$name]);
  }

  /**  As of PHP 5.1.0  */
  public function __unset($name)
  {
    echo "\n\nI am in __unset()\n\n";

    echo "Unsetting '$name\n\n";
    unset($this->data[$name]);
  }

}



$obj = new PropertyTest;
$obj->a = 1;

echo $obj->a;

var_dump(isset($obj->a));

unset($obj->a);

var_dump(isset($obj->a));
echo "\n\n";

